package com.rfy.swagger.config;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhang
 * @创建时间 2019年07月15日
 * @描述: Swagger配置类, 开启在线接口文档和添加相关配置
 * @EnableSwagger2 表示开启Swagger2
 **/

@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List resources = new ArrayList<>();
        resources.add(swaggerResource("default", "/v2/api-docs", "2.0"));
        resources.add(swaggerResource("用户模块", "/rfy/user/v2/api-docs", "2.0"));
        resources.add(swaggerResource("小说模块", "/rfy/novel/v2/api-docs", "2.0"));
        resources.add(swaggerResource("音乐模块", "/rfy/music/v2/api-docs", "2.0"));
        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}